/**
 * FileName: OrderImpl
 * Author:   杨兴
 * Date:     2019/8/14 10:24
 * Description: 订单实现
 */
package com.xiongmao.gongyu.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderImpl implements OrderInterface{
    private static final String url = "http://localhost:8010/getMemberData";

    @Value("${server.port}")
    private String server_port;
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private MemberInteface memberInteface;

    @Autowired
    private MemberInteface2 memberInteface2;

    @RequestMapping("/orderToMember2")
    public String orderToMember2(){
        String name = "yangxing";
        System.out.println(System.currentTimeMillis());
        return memberInteface2.getMemberData(name);
    }
    @RequestMapping("/orderToMember3")
    public String orderToMember3(){
        System.out.println(System.currentTimeMillis());
        return memberInteface2.testMybatis();
    }
    @HystrixCommand(fallbackMethod = "fallBackString")
    @RequestMapping("/orderToMember")
    public String orderToMember(){
//        String yangxing = restTemplate.getForObject(url, String.class, "yangxing");
        System.out.println(System.currentTimeMillis());
        System.out.println("进入订单服务当前线程名称"+Thread.currentThread().getName());
        String yangxing = memberInteface.getMemberData("yangxing");
//        String yangxing ="yangxing";
        System.out.println(yangxing);

        System.out.println(System.currentTimeMillis());
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("当前线程名称"+Thread.currentThread().getName()+yangxing);
        return yangxing;
    }
    public String fallBackString(){
        System.out.println(System.currentTimeMillis());
        System.out.println("服务降级线程名称"+Thread.currentThread().getName());
        return "服务降级order";
    }
    @Override
    @RequestMapping("/orderInfo")
    public String orderInfo() {
//        System.out.println(timeOutMillons);
        System.out.println(server_port);
        System.out.println(System.currentTimeMillis());
        System.out.println("线程名称"+Thread.currentThread().getName());
        String yangxing = memberInteface.getMemberData("yangxing");
        return yangxing;
    }
}
